import axios from 'axios'
// import store from '@/store'
// import { getToken } from '@/utils/auth'

// create an axios instance
// const config = process.env.NODE_ENV === 'development' ? {timeout: 5000} : {baseURL: process.env.BASE_API, timeout: 5000}
const service = axios.create({
  // baseURL: process.env.BASE_API, // api的base_url
  timeout: 5000 // request timeout
  // headers: {'Access-Control-Allow-Origin': '*'}
  // headers: {'Access-Control-Allow-Origin': '*'}
})

// request interceptor
service.interceptors.request.use(config => {
  // Do something before request is sent
  // if (store.getters.token) {
  //   config.headers['X-Token'] = getToken() // 让每个请求携带token-- ['X-Token']为自定义key 请根据实际情况自行修改
  // }
  return config
}, error => {
  // Do something with request error
  console.log(error) // for debug
  Promise.reject(error)
})

// respone interceptor
service.interceptors.response.use(
    response => {
      return Promise.resolve(response.data)
    },
  error => {
    console.log('err' + error)// for debug
    return Promise.reject(error)
  })

export default service
